

import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import axios from "axios";

const app = createApp(App)
app.use(ElementPlus)
app.use(createPinia())
app.use(router)

app.mount('#app')
//设置axios的基础url部分
axios.defaults.baseURL = '/api/';

// const tokenSession=TokenSessionStorage();
// 获取存储在 localStorage 中的 token



router.beforeEach(function(to,from,next){
    const user = sessionStorage.getItem('user');
    //除了登录、注册、首页、商家列表、商家信息之外，都需要判断是否登录
    if(!(to.path==='/'||to.path==='/customer/index'||to.path==='/login'||to.path==='/register')){
        if(user==null){
            router.push({path: '/login'});
        }
    }
    next();
});
